package net.aiotos.driver;

import Glacier2.SessionNotExistException;
import Ice.Current;
import IceUtilInternal.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import net.aiotos.sdk.IOTOSysI;
import net.aiotos.driver.custom.ZMCollEngine;
import net.aiotos.driver.custom.ZMControlEvent;
import net.aiotos.common.ice.HeartBeatThread;
import net.aiotos.common.ice.RefreshSessionThread;
import net.aiotos.common.ice.WebSessionRefreshThread;
import net.aiotos.common.ice.routellib.CallbackReceiverDisp;
import net.aiotos.common.util.ReadIO;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.aiotos.common.dto.*;

import java.io.File;
import java.util.*;


/**
 * 驱动进程管理类
 */
@Slf4j
public class IOTOSys {
    public final String runDir;
    @Getter
    public final IOTOSysI iotoSysI;
    private final Object lock = new Object();
    @Deprecated
    public List<String> mdevIdList = new ArrayList<String>(); //设备id集合
    @Deprecated
    public Map<String, DeviceDTO> mdevAttrs = new HashMap<>();  //设备id+属性的键值对集合
    /**
     * 	设备-监测点列表字典：{“[网关ID].[设备ID]”:[“[网关ID].[设备ID].[数据点ID]”]}
     */
    @Deprecated
    public Map<String, List<String>> mdevpoints = new HashMap<String, List<String>>();  //设备下的点集合
    @Deprecated
    public  Map<String, DataDTO> mpointAttrs = new HashMap<>();     //点的属性集合
    /**
     * 监测点-订阅字典:{“[网关ID].[设备ID].[数据点ID]”:[“[设备ID].[数据点ID]”,”[设备ID].*”]}
     */
    public Map<String, List<String>> mpoint2subs = new HashMap<String, List<String>>();
    @Deprecated
    public Map<String, IOTOSDriverI> mdev2driver = new HashMap<String, IOTOSDriverI>();
    private final List<RunCollectionThread> threadingList = new ArrayList<RunCollectionThread>();  //线程集合
    @Deprecated
    private ZMControlEvent ctEvent;
    @Deprecated
    private ZMCollEngine clEvent;
    public int eventcount;  //采集个数
    public boolean startCollect = false;  //启动采集
    public boolean pauseCollect = false; //暂停采集
    public boolean restartCollect = false; //采集复位
    public boolean startConnect = false;
    private volatile boolean event;

    private WebSessionRefreshThread webSessionRefreshThread = null;
    private RefreshSessionThread refreshSessionThread = null;
    private HeartBeatThread heartBeatThread = null;

    public IOTOSys(String runDir) {
        this.runDir = runDir;
        this.iotoSysI = new IOTOSysI(runDir);
    }

    public IOTOSys(@NonNull IOTOSysI iotoSysI) {
        this.runDir = iotoSysI.runDir;
        this.iotoSysI = iotoSysI;
    }

    public void  destroy() throws SessionNotExistException {
        iotoSysI.iceService.destroy();
    }

    protected CallbackReceiverDisp callback = new CallbackReceiverDisp() {
        @Override
        public String callback(String fromUuid, String data, Current __current) {
            log.info("callback:{}, {}", fromUuid, data);
            CallbackDTO info = JSONObject.parseObject(data, CallbackDTO.class);
            final CallbackTypeEnum info_type = info.type;
            // 连接网络，连接复位
            if(info_type == CallbackTypeEnum.ioServerConnectServer
                    || info.type == CallbackTypeEnum.ioServerReConnectServer) {
                startConnect = true;
            }

            // startConnect 相关功能未支持，暂时隐藏吧
//            if(startConnect == false) {
//                return ResultDTO.ret(101, "Network disconnection", info).toString();
//            }

            // 断开网络
//            if(info_type == CallbackTypeEnum.ioServerDisconnectServer) {
//                startConnect = false;
//            }

            // 启动采集，停止采集，采集复位
            if(info_type == CallbackTypeEnum.devStartCollect) {
                startCollect = true;
                pauseCollect = false;
                restartCollect = false;
                event = true;
            }

            if(info_type == CallbackTypeEnum.devPauseCollect) {
                startCollect = false;
                pauseCollect = true;
                restartCollect = false;
            }

            if(info_type == CallbackTypeEnum.devResetCollect) {
                startCollect = false;
                pauseCollect = true;
                restartCollect = true;
            }

            // startConnect 相关功能未支持，暂时隐藏吧
//            if(startCollect == false) {
//                return ResultDTO.ret(0, "OK", info).toString();
//            }

            if(info_type == CallbackTypeEnum.getData || info_type == CallbackTypeEnum.setData || info_type == CallbackTypeEnum.syncPubMsg) {
                IonodeDTO ionodeDTO = info.getBody().toJavaObject(IonodeDTO.class);

                String ionodeId = ionodeDTO.getId();
                String deviceOid = null;
                String dataOid = null;

                for (Map.Entry<String, DeviceDTO> deviceDTOEntry : ionodeDTO.getProperties().entrySet()) {
                    deviceOid = deviceDTOEntry.getKey();
                    DeviceDTO deviceDTO = deviceDTOEntry.getValue();
                    dataOid = deviceDTO.getData().keySet().toArray(new String[]{})[0];
                }

                String point = String.format("%s.%s.%s", ionodeId, deviceOid, dataOid);
                String devId = String.format("%s.%s", ionodeId, deviceOid);

                String dataValue = ionodeDTO.getProperties().get(deviceOid).getData().get(dataOid).getValue();
                // 读写属性
                ResultDTO resultDTO = null;
                try {
                    resultDTO = iotoSysI.getTableDetail();
                } catch (Exception exception) {
                    exception.printStackTrace();
                    return resultDTO.toString();
                }

                IonodeDTO newIonodeDTO = resultDTO.toJavaObject(IonodeDTO.class);
                // 获取点表详情来判断读写属性
                Integer readwrite = newIonodeDTO.getProperties().get(deviceOid).getData().get(dataOid).getReadwrite();
                String valType = newIonodeDTO.getProperties().get(deviceOid).getData().get(dataOid).getValuetype();

                if(info_type == CallbackTypeEnum.getData) {
                    if(readwrite == 2) {
                        return ResultDTO.ret(515, "PropertyNotValid").toString();
                    }

                    // 传给用户驱动程序的是剥离掉接入点、设备ID之后纯粹监测点ID，因为用户驱动本身知道自己对应的设备ID，只用data_id就可以唯一识别对应自己的监测点接口
                    ResultDTO getDataResultDto = driver(devId).Event_getData(dataOid, dataValue);
                    if(getDataResultDto.getCode() != ErrorEnum.Successfull) {
                        return getDataResultDto.toString();
                    }
                    return cmdData(point, getDataResultDto).toString();

                }
                if(info_type == CallbackTypeEnum.setData) {
                    if(readwrite == 1) {
                        return ResultDTO.ret(515, "PropertyNotValid").toString();
                    }

                    ResultDTO setDataResultDto = driver(devId).Event_setData(dataOid, dataValue);
                    if(setDataResultDto.getCode() != ErrorEnum.Successfull) {
                        return setDataResultDto.toString();
                    }
                    return cmdData(point, setDataResultDto).toString();

                }
                if(info_type == CallbackTypeEnum.syncPubMsg) {
                    DeviceConfigDTO deviceConfigDTO = iotoSysI.getIonodeDTO()
                                                              .getProperties()
                                                              .get(deviceOid)
                                                              .getConfig()
                                                              .toJavaObject(DeviceConfigDTO.class);

                    String cfg = deviceConfigDTO.getParam(DeviceConfigParamDTO.class).getFilter();

                    String[] strings = StringUtil.splitString(cfg, ".");
                    String ioId = strings[0];
                    String deId = strings[1];
                    String daId = strings[2];
                    ResultDTO resultDTO1 = null;
                    for (int i = 0; i < cfg.length(); i++) {
                        if(deId.equals("*")) {
                            for (Map.Entry<String, IOTOSDriverI> driverIEntry : mdev2driver.entrySet()) {
                                String did = driverIEntry.getKey();
                                IOTOSDriverI devdr = driverIEntry.getValue();
                                ResultDTO eventSyncPubMsgResult = driver(did).Event_syncPubMsg(point, dataValue);
                                if(eventSyncPubMsgResult.getCode() != ErrorEnum.Successfull) {
                                    return eventSyncPubMsgResult.toString();
                                }
                                if(daId.equals("*")) {
                                    resultDTO1 = driver(ioId+"."+deId).Event_syncPubMsg(point, dataValue);
                                } else {
                                    resultDTO1 = driver(ioId+"."+deId).Event_syncPubMsg(ioId+"."+deId+"."+daId, dataValue);
                                }
                            }
                        }
                    }
                    return cmdData(point, resultDTO1).toString();

                }

            }
            CallbackBodyDTO callbackBodyDTO;
            try {
                callbackBodyDTO = info.getBody().toJavaObject(CallbackBodyDTO.class);
            } catch (Exception ex) {
                ex.printStackTrace();
                return ResultDTO.ret(101, ex.getMessage()).toString();
            }

            if(info_type == CallbackTypeEnum.notify && callbackBodyDTO.getNotifyType().equals("data_update")) {
                log.warn("收到后端网关更新通知:{},{}", info_type.name(), callbackBodyDTO.getNotifyType());
                try {
                    loginIce(); // java 重新刷新
                    return ResultDTO.code(0).toString();
                } catch (Exception exception) {
                    exception.printStackTrace();
                    return ResultDTO.ret(514, exception.getMessage()).toString();
                }
            }

            if(info_type == CallbackTypeEnum.sendMsg) {
                List<HashMap> retArray = new ArrayList<>();

                for (Map.Entry<String, IOTOSDriverI> driverIEntry : mdev2driver.entrySet()) {
                    String deviceOid = driverIEntry.getKey();
                    IOTOSDriverI driverI = driverIEntry.getValue();
                    ResultDTO resultDTO = driverI.Event_customBroadcast(fromUuid, info_type, JSONObject.toJSONString(info.getBody()));
                    HashMap<String, ResultDTO> map = new HashMap<>();
                    map.put("did", resultDTO);
                    retArray.add(map);
                }
                return ResultDTO.ret(0, "OK", retArray).toString();
            }
            return ResultDTO.ret(0, "没有匹配到处理规划").toString();
        }
    };

    protected ResultDTO cmdData(String point, ResultDTO resultDTO) {
        return ResultDTO.ret(514, "cmdData NotImplementedException");
    }

    /**
     * 获取驱动类
     *
     * @param devid
     * @return
     */
    public IOTOSDriverI driver(String devid) {
        return this.mdev2driver.get(devid);
    }

    /**
     * 设备上线上报
     * @return
     */
    public ResultDTO DevOnline(String[] devsId) throws Exception {
        String deviceOid = null;
        ResultDTO resultDTO = new ResultDTO();
        try {
            for (String devId : devsId) {
                deviceOid = StringUtil.splitString(devId, ".")[1];
                resultDTO = iotoSysI.devOnline(deviceOid);
                if (resultDTO.getCode() != ErrorEnum.Successfull) {
                    throw new Exception("设备上线失败");
                }
            }
            return resultDTO;
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * 设备下线上报
     *
     * @param devsId
     * @return
     */
    public ResultDTO DevOffine(String[] devsId) {
        String deviceOid = null;
        ResultDTO resultDTO = new ResultDTO();
        try {
            for (String devId : devsId) {
                deviceOid = devId.split("\\.")[1];
                resultDTO = iotoSysI.devOffline(deviceOid);
            }
            return resultDTO;
        } catch (Exception e) {
            log.error("设备下线失败：{}", deviceOid, e);
            resultDTO.setCode(ErrorEnum.valueOf(514));
            resultDTO.setMsg("Argument error");
        }
        return resultDTO;
    }

    /**
     * 解析单张表数据
     * @param ionodeDTO IonodeDTO
     * @return
     */

    public ResultDTO engineInit(@NonNull IonodeDTO ionodeDTO) throws Exception {
        try {
            if (ionodeDTO.getId() == null || ionodeDTO.getName() == null || ionodeDTO.getDescription() == null ||
                    ionodeDTO.getTimestamp() == 0 ||  ionodeDTO.getLongitude() == null || ionodeDTO.getLatitude() == null ||
                    ionodeDTO.getOwner() == null || ionodeDTO.getConfig() == null || ionodeDTO.getProperties() == null) {
                throw new Exception("Table format invalid");
            }


            // 自动补全配置参数
            autoCompleteConfig();

        } catch (Exception e) {
            // 配置递归补全失败
            throw e;
        }

        // 初始化全局属性
        getDevList();

        //开启多线程
        for (int i = 0; i < mdevIdList.size(); i++) {
            String str = mdevIdList.get(i);
            try {
                RunCollectionThread r = new RunCollectionThread(this, lock, str);
                this.threadingList.add(r);
            } catch (ClassNotFoundException ex) {
                log.error("ClassNotFoundException", ex);
            }

        }
        return ResultDTO.code(0);
    }


    private void autoCompleteConfig() throws Exception {
        //修改设备config
        Map<String, DeviceDTO> deviceDTOMap = getIotoSysI().getIonodeDTO().getProperties();
        JSONObject deviceConfigMap = new JSONObject();
        for (Map.Entry<String, DeviceDTO> entry : deviceDTOMap.entrySet()) {
            deviceConfigMap.put(entry.getKey(), entry.getValue().getConfig(JSONObject.class));
        }

        for (Map.Entry<String, DeviceDTO> deviceDTOEntry : deviceDTOMap.entrySet()) {
            String deviceOid = deviceDTOEntry.getKey();
            DeviceDTO deviceDTO = deviceDTOEntry.getValue();
            if (deviceDTO.getName() == null ||
                    deviceDTO.getDescription() == null ||
                    deviceDTO.getConfig() == null ||
                    deviceDTO.getData() == null ) {
                throw new Exception("Table format invalid");
            }

            //递归补全
            _ParseTableData(deviceDTO.getConfig(), deviceOid, deviceConfigMap);
            //补全data config
            Map<String, DataDTO> dataConfig = deviceDTO.getData();
            JSONObject dataConfigMap = new JSONObject();
            for (Map.Entry<String, DataDTO> entry : dataConfig.entrySet()) {
                deviceConfigMap.put(entry.getKey(), entry.getValue().getConfig());
            }

            for (Map.Entry<String, DataDTO> entry : dataConfig.entrySet()) {
                String dk = entry.getKey();
                DataDTO dataDTO = entry.getValue();
                if(dataDTO.getName().isEmpty() ||
                        dataDTO.getReadwrite() == null ||
                        dataDTO.getMaxvalue() == null ||
                        dataDTO.getMinvalue() == null ||
                        dataDTO.getRegexp() == null ||
                        dataDTO.getSensibility() == null ||
                        dataDTO.getConfig() == null ||
                        dataDTO.getValuetype() == null) {
                    throw new Exception("Table format invalid");
                }

                //递归补全
                _ParseTableData(dataDTO.getConfig(), dk, dataConfigMap);
            }
        }
    }

    /**
     * 启动采集
     *
     * @return
     */
    @SuppressWarnings({"static-access", "unused"})
    public ResultDTO engineRun() {
        if (this.threadingList.size() > 0) {
            for (RunCollectionThread r : this.threadingList) {
                r.start();
            }
            return ResultDTO.code(0).msg("OK");
        } else {
            return ResultDTO.code(-1).msg("OK");
        }
    }

    /**
     * 退出采集
     *
     * @return
     */
    @SuppressWarnings("deprecation")
    public ResultDTO engineStop() {
        if (threadingList.size() > 0) {
            for (RunCollectionThread tr : threadingList) {
                //停止线程
                tr.stop();
            }
            return ResultDTO.code(0).msg("OK");
        } else {
            return ResultDTO.code(0).msg("OK");
        }
    }

    /**
     * 线程个数
     *
     * @return
     */
    @SuppressWarnings("static-access")
    public int count() {
        return eventcount;
    }

    /**
     * 递归补全
     */
    private JSONObject _ParseTableData2(String currentId, Map<String, JSONObject> jsonObjectMap) {
        final String parentIdKey = "parentId";
        final String paramKey = "param";

        JSONObject currentObject = jsonObjectMap.get(currentId);
        if (!currentObject.containsKey(parentIdKey)) {
            return currentObject;
        }

        String parentId = currentObject.getString(parentIdKey);
        if (!jsonObjectMap.containsKey(parentId)) {
            log.error("parentId:{},没有这个上线配置", parentId);
            return currentObject;
        }
        JSONObject parentObject = jsonObjectMap.get(parentId);
        if (parentObject.containsKey(parentIdKey)) ;
        return null;
    }


    private void _ParseTableData(JSONObject param, String id, JSONObject body) {
        JSONObject config = null;
        String parentId = null;
        try {
            config = param.getJSONObject("config");
        } catch (Exception e) {
            return;
        }

        if (config != null) {
            try {
                parentId = config.getString("parentId");
            } catch (Exception e) {
                try {
                    parentId = config.getString("parentid");
                } catch (Exception e2) {
                    return;
                }
            }
        }

        JSONObject myparam = new JSONObject();
        JSONObject youparam = new JSONObject();
        if (null != parentId && !"".equals(parentId)) {
            try {
                myparam = param.getJSONObject("config").getJSONObject("param");
            } catch (Exception e) {
                // TODO: handle exception
            }

            try {
                youparam = body.getJSONObject(parentId).getJSONObject("config").getJSONObject("param");
            } catch (Exception e) {
                // TODO: handle exception
            }

            if (myparam.size() > 0) {
                for (String mk : myparam.keySet()) {
                    if (!youparam.containsKey(mk)) {
                        youparam.put(mk, myparam.getString(mk));
                    }
                }
            }

            body.getJSONObject(id).getJSONObject("config").put("param", youparam);
            try {
                this._ParseTableData(body.getJSONObject(parentId), parentId, body);
            } catch (Exception e) {
                return;
            }

        }
    }

    /**
     * 获取设备信息
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    public void getDevList() {
        String ionodeId = getUuid(); //资源id
        mdevIdList.clear();
        mdevAttrs.clear();
        mpointAttrs.clear();
        mpoint2subs.clear();
        mdevpoints.clear();
        Map<String, DeviceDTO> infoProp = iotoSysI.getIonodeDTO().getProperties(); //设备对象集合
        for (Map.Entry<String, DeviceDTO> dtoEntry : infoProp.entrySet()) {
            String deviceKey = dtoEntry.getKey();
            DeviceDTO deviceDTO = dtoEntry.getValue();
            List<String> devPoint = new ArrayList<String>();
            String idInfo = ionodeId + "." + deviceKey;
            mdevIdList.add(idInfo); //设备ids
            mdevAttrs.put(idInfo, deviceDTO); //设备attr

            // 设备属性data
            Map<String, DataDTO> devData = deviceDTO.getData();
            for (Map.Entry<String, DataDTO> dataDTOEntry : devData.entrySet()) {
                String dataK = dataDTOEntry.getKey();
                DataDTO dataDTO = dataDTOEntry.getValue();
                String pointId = idInfo + "." + dataK;
                devPoint.add(pointId);
                mpointAttrs.put(pointId, dataDTO); // 点属性
                // group
                List<String> group = new ArrayList<String>();
                List<String> group_list = this._get_group(iotoSysI.getIonodeDTO(), deviceKey, dataK, group);
                mpoint2subs.put(pointId, group_list);
                mdevpoints.put(idInfo, devPoint);
            }
        }

        Map<String, Object> retMap = new HashMap<String, Object>();
    }

    @Deprecated
    private List<String> _get_group(IonodeDTO infos, String device_id, String data_id, List<String> group) {
        Map<String, DeviceDTO> info = infos.getProperties();
        for (Map.Entry<String, DeviceDTO> dtoEntry : info.entrySet()) {
            String device_id2 = dtoEntry.getKey();
            DeviceDTO deviceDTO = dtoEntry.getValue();
            try {
                String[] de = deviceDTO.getConfig(DeviceConfigDTO.class).getParam(DeviceConfigParamDTO.class).getSub();
                for (String device_data : de) {
                    String sub_device_id = device_data.split("\\.")[0];
                    String sub_data_id = device_data.split("\\.")[1];
                    if (sub_device_id.equals(device_id)) {
                        if ("*".equals(sub_data_id) || data_id.equals(sub_data_id)) {
                            if (!group.contains(device_id2)) {
                                group.add(device_id2);
                            }
                        }
                    }

                }
            } catch (Exception e) {

            }
        }
        return group;
    }

    /**
     * 连接通信服务
     * @return
     * @throws Exception
     */
    public LoginResp loginIce() throws Exception {
        LoginDTO webLoginParam = iotoSysI.getLoginDTO();
        LoginResp loginResp = iotoSysI.login(webLoginParam, this.callback);
        return loginResp;
    }


    /**
     * 登录接口
     *F
     * @return
     * @throws Exception
     */
    public ResultDTO Login(LoginDTO webLoginParam) throws Exception {
        iotoSysI.setLoginDTO(webLoginParam);
        LoginResp loginResp = loginIce();
        String tableInfoMes = null;
        ResultDTO resultInfo = iotoSysI.ret(loginResp.getCode(), loginResp.getMsg());

        if (!(loginResp.getCode() != null && loginResp.getCode() == 0)) {
            return resultInfo;
        }
        iotoSysI.setUuid(webLoginParam.uuid);

        //sdk处理
        //获取平台传过来的表信息
        ResultDTO msg = iotoSysI.getTableDetail();
        if (msg.getCode() != ErrorEnum.Successfull) {
            return iotoSysI.ret(msg.getData(), msg.getCode().code, msg.getMsg());
        }

        String iceTableInfo = msg.toString();
        log.info("table:{}", msg.getData().toJSONString());
        IonodeDTO ionodeDTO = msg.toJavaObject(IonodeDTO.class);

        // 如果本地点表id与平台id不同直接覆盖
        IonodeDTO localIonodeDTO = readTable(iotoSysI.getUuid());

        resultInfo = iotoSysI.ret(null, msg.getCode().code, msg.getMsg());
        if (localIonodeDTO == null) {
            writeTable(ionodeDTO);
        } else {
            long tableTimes = localIonodeDTO.getTimestamp();
            long iceTableTimes = ionodeDTO.getTimestamp();

            //平台数最新直接覆盖本地
            if (iceTableTimes > tableTimes) {
                localIonodeDTO = msg.getData().toJavaObject(IonodeDTO.class);
                writeTable(ionodeDTO);
            } else {
                //本地数据新执行update
                ResultDTO resultDTO = iotoSysI.updateTable(localIonodeDTO);
                localIonodeDTO = resultDTO.getData().toJavaObject(IonodeDTO.class);
                resultInfo = iotoSysI.ret(null, resultDTO.getCode().code, resultDTO.getMsg());
            }
        }

        iotoSysI.setIonodeDTO(ionodeDTO);
//        //补全点表信息
//        ResultDTO engineInit = engineInit(ionodeDTO);
//        log.info("engineInit => {}", engineInit);

        // 启动守护
        webSessionRefreshThread = new WebSessionRefreshThread(iotoSysI);
        webSessionRefreshThread.start();

        heartBeatThread = new HeartBeatThread(iotoSysI); // 向服务器发送心跳监测
        heartBeatThread.start();

        refreshSessionThread = new RefreshSessionThread(iotoSysI);
        refreshSessionThread.start();

        log.info("IOTOSysI Communication Services Starting Success!!!");
        return resultInfo;
    }

    private IonodeDTO readTable(String uuid) {
        //读取本地点表信息
        String fileName = String.format("%s/cache/%s.json", runDir, uuid);
        File tbFile = new File(fileName);
        String tableInfo = ReadIO.readFile(tbFile);
        IonodeDTO ionodeDTO = JSONObject.parseObject(tableInfo, IonodeDTO.class);
        return ionodeDTO;
    }

    private void writeTable(IonodeDTO ionodeDTO) {
        //读取本地点表信息
        String cacheDir = String.format("%s/cache/", runDir);
        String fileName = String.format("%s/cache/%s.json", runDir, ionodeDTO.getId());
        File tbFile = new File(fileName);
        try {
            new File(cacheDir).mkdir();
        } catch (Exception ex) {
            log.info("创建缓存目录失败", ex);
            throw ex;
        }
        String tableInfoMes = JSON.toJSONString(ionodeDTO, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        ReadIO.writeFile(tableInfoMes, tbFile);
    }

    public String getUuid() {
        return iotoSysI.getUuid();
    }

    public ResultDTO PubMsg(String pointId, String value) throws Exception {
        return iotoSysI.PubMsg(pointId, value);
    }

    public List<ResultDTO> PubMsgs(List<DataPubDTO> values) throws Exception {
        return iotoSysI.PubMsgs(values);
    }
}
